/*
 * How to build:
 *   make lua LDFLAGS=-llua
 */

#include <stdio.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

int
main(void)
{
	char buf[BUFSIZ];
	int res;
	lua_State *lua = lua_open();
	luaL_openlibs(lua);
	while (fgets(buf, BUFSIZ, stdin) != NULL) {
		res = luaL_loadbuffer(lua, buf, strlen(buf), "oops") ||
			lua_pcall(lua, 0, 0, 0);
		if (res != 0) {
			fprintf(stderr, "%s\n", lua_tostring(lua, -1));
			lua_pop(lua, 1);
		}
	}
	lua_close(lua);
	return 0;
}
